﻿package ygg.encoding.amf.type.v3
{
	import flash.xml.XMLDocument;
	import ygg.encoding.amf.type.*;
	import j.sus2maj7.encoding.*;
	
	public class XmlDocCodec extends ComplexCodec
	{
		public function XmlDocCodec()
		{
			
		}
		
		override protected function decodeComplex(u:uint, binary:IBinary, context:IContext=null):*
		{
			return new XMLDocument( binary.readUTFBytes( u) );
		}
		
		override protected function encodeComplex(o:Object, b:IBinary, context:IContext=null):void
		{
			var x:XMLDocument = o as XMLDocument;
			var s:String = x.toString();
			b.writeByte( s.length << 1 | 1 );
			b.writeUTFBytes( s );
			
		}
		override protected function getMarker():uint
		{
			return Amf3Marker.XML_DOC;
		}
	}
}